package lc;

import org.junit.Test;

public class Ex45 {
    class Solution {
        public int jump(int[] nums) {
            int n = nums.length;
            if (n <= 1) {
                return 0;
            }
            int max = nums[0], s = 1, t = 0, res = 1;
            for (int i = 1; i < n; i++) {
                t = Math.max(i + nums[i], t);
                if (i <= max) {
                    res = s;
                } else {
                    max = t;
                    s++;
                    res = s;
                }
            }
            return res;
        }
    }
    
    @Test
    public void test() {
        Solution s = new Solution();
        int[] nums = new int[]{1,1,1,1};
        System.out.println(s.jump(nums));
        
    }
}
